//选择农药产品登记证号
layui.use(['form', 'layer', 'laydate', 'table'], function () {
    let form = layui.form;
    let layer = layui.layer;
    let laydate = layui.laydate;
    let table = layui.table;
    //获取数据上报查询url
    let upreportUrl = apiArr[9].trim();
    //获取处理详情下载url
    let filePathUrl = apiArr[10].trim();

    //方法级渲染
    table.render({
        elem: '#LAY_table_user',
        //url: 'http://127.0.0.1/yj/upreportQuery',
        url: upreportUrl,
        where: {
            departmentId: window.top.companyinfo.departmentId,
            sidx: 'reportTime',
            sord: 'desc'
        },
        cols: [
            [{
                    type: 'numbers',
                    fixed: true //显示序号
                }, {
                    field: 'id',
                    title: '查询ID',
                    fixed: true
                }, {
                    field: 'reportType',
                    title: '上报类型',
                    fixed: true
                }, {
                    field: 'reportTime',
                    title: '上报时间',
                    fixed: true,
                    sort: true,
                    templet: function (d) {
                        return new Date(d.reportTime).format('yyyy-MM-dd hh:mm:ss');
                    }
                }, {
                    field: 'reportCodeNum',
                    width: 120,
                    title: '上报条数',
                    fixed: true,
                }, {
                    field: 'processStatus',
                    title: '处理状态',
                    fixed: true,
                },
                /* {
                               field: 'reportFilePath',
                               title: '上报xml文件详情',
                               fixed: true,
                               templet: function (d) {
                                   return '<a href="#" class="aqua-color" onclick="downfile(\'' + filePathUrl + d.reportFilePath + '\')">xml文件</a>';
                               }
                           }, */
                {
                    field: 'processResFilepath',
                    title: '处理详情',
                    fixed: true,
                    templet: function (d) {
                        if (d.processResFilepath) {
                            return '<a href="#" class="aqua-color" onclick="downfile(\'' + filePathUrl + d.processResFilepath + '\')">处理详情</a>';
                        } else {
                            return '';
                        }
                    }
                }
            ]
        ],
        parseData: function (res) { //res 即为原始返回的数据
            return {
                "code": res.code, //解析接口状态
                "msg": res.message, //解析提示文本
                "count": res.records, //解析数据长度
                "data": res.rows //解析数据列表
            };
        },
        request: {
            pageName: 'page', //页码的参数名称，默认：page
            limitName: 'rows' //每页数据量的参数名，默认：limit
        },
        id: 'testReload',
        even: true,
        page: true,
        height: 'full-120',
        limit: 20,
        limits: [10, 20, 30, 50]

    });
    //执行一个laydate实例
    laydate.render({
        elem: '#reportTime' //指定元素
    });
    //执行一个laydate实例
    laydate.render({
        elem: '#endDate' //指定元素
    });

    let $ = layui.$,
        active = {
            reload: function () {
                var q = formSearchCollection();
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    },
                    where: {
                        queryJson: json2Str({
                            groupOp: 'AND',
                            rules: q
                        })
                    },
                    height: 'full-120',
                });
            }
        };
    $('.demoTable .layui-btn').on('click', function () {
        let type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });

});

function downfile(downloadPath) {
    choseDirectoryAndDownload(downloadPath);

}